<%--
  Created by IntelliJ IDEA.
  User: xugang2
  Date: 2020/7/22
  Time: 14:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <%@ include file="/WEB-INF/pages/include/base_css.jsp"%>

    <style>
        .tree li {
            list-style-type: none;
            cursor:pointer;
        }
        table tbody tr:nth-child(odd){background:#F4F4F4;}
        table tbody td:nth-child(even){color:#C00;}
    </style>
</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container-fluid">
        <div class="navbar-header">
            <div><a class="navbar-brand" style="font-size:32px;" href="#">众筹平台 - 用户维护</a></div>
        </div>

        <%@include file="/WEB-INF/pages/include/manager_loginbar.jsp"%>

    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <%@include file="/WEB-INF/pages/include/manager_menu.jsp"%>

        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form action="${PATH}/admin/index" class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <%-- 访问分页数据时请求又会转发回来，可以从请求参数中获取condition回显
                                    ${xxxScope.condition} :全域查询，从域中获取
                                    url?id=11&condition=xxx
                                    param = {id=1 , confition=xxx}
                                    el有11个内置对象： param 请求参数的map集合
                                --%>
                                <input name="condition" value="${param.condition}" class="form-control has-success" type="text" placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询</button>
                    </form>
                    <button type="button" id="batchDelBtn" class="btn btn-danger" style="float:right;margin-left:10px;"><i class=" glyphicon glyphicon-remove"></i> 删除</button>
                    <button type="button" class="btn btn-primary" style="float:right;" onclick="window.location='${PATH}/admin/add.html'"><i class="glyphicon glyphicon-plus"></i> 新增</button>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr >
                                <th width="30">#</th>
                                <th width="30"><input type="checkbox"></th>
                                <th>账号</th>
                                <th>名称</th>
                                <th>邮箱地址</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                                <c:forEach items="${pageInfo.list}" varStatus="vs" var="admin">
                                    <tr>
                                        <td>${vs.count}</td>
                                        <td><input adminid="${admin.id}" type="checkbox"></td>
                                        <td>${admin.loginacct}</td>
                                        <td>${admin.username}</td>
                                        <td>${admin.email}</td>
                                        <td>
                                            <button adminid="${admin.id}" type="button" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></button>
                                            <%-- 更新按钮 --%>
                                            <button adminid="${admin.id}" type="button" class="btn btn-primary btn-xs"><i class=" glyphicon glyphicon-pencil"></i></button>
                                            <%-- 删除单个管理员的按钮 --%>
                                            <button type="button" onclick="window.location='${PATH}/admin/delete?id=${admin.id}&pageNum=${pageInfo.pageNum}'" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></button>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </tbody>
                            <tfoot>
                            <tr >
                                <td colspan="6" align="center">
                                    <ul class="pagination">
                                        <c:choose>
                                            <c:when test="${pageInfo.hasPreviousPage}">
                                                <%-- 有上一页 --%>
                                                <li><a href="${PATH}/admin/index?pageNum=${pageInfo.prePage}&condition=${param.condition}">上一页</a></li>
                                            </c:when>
                                            <c:otherwise>
                                                <%-- 没有上一页--%>
                                                <li class="disabled"><a href="javascript:void(0);">上一页</a></li>
                                            </c:otherwise>
                                        </c:choose>
                                        <c:forEach items="${pageInfo.navigatepageNums}" var="index">
                                            <c:choose>
                                                <c:when test="${pageInfo.pageNum==index}">
                                                    <%-- 正在遍历当前页码 高亮显示--%>
                                                    <li class="active"><a href="javascript:void(0)">${index} <span class="sr-only">(current)</span></a></li>
                                                </c:when>
                                                <c:otherwise>
                                                    <li><a href="${PATH}/admin/index?pageNum=${index}&condition=${param.condition}">${index}</a></li>
                                                </c:otherwise>
                                            </c:choose>
                                        </c:forEach>
                                        <%-- 下一页 --%>
                                        <c:choose>
                                            <c:when test="${pageInfo.hasNextPage}">
                                                <%-- 有下一页 --%>
                                                <li><a href="${PATH}/admin/index?pageNum=${pageInfo.nextPage}&condition=${param.condition}">下一页</a></li>
                                            </c:when>
                                            <c:otherwise>
                                                <%-- 没有下一页--%>
                                                <li class="disabled"><a href="javascript:void(0);">下一页</a></li>
                                            </c:otherwise>
                                        </c:choose>
                                    </ul>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<%@include file="/WEB-INF/pages/include/base_js.jsp"%>
<script type="text/javascript">
    //批量删除复选框的全选效果
    $("thead :checkbox").click(function () {
        $("tbody :checkbox").prop("checked" , this.checked);//设置子复选框的选中状态  prop设置标签的自带属性
    });
    $("tbody :checkbox").click(function () {
        //获取被选中的子复选框的数量，如果和所有的子复选框数量一样，那么设置全选框选中
        $("thead :checkbox").prop("checked" , $("tbody :checkbox").length == $("tbody :checkbox:checked").length)
    });
    //批量删除按钮的单击事件
    $("#batchDelBtn").click(function () {
        //获取要被删除的管理员的id列表[被选中的子复选框所在行的管理员id]
        var adminids = new Array();
        $("tbody :checkbox:checked").each(function () {
            var adminid = $(this).attr("adminid");
            adminids.push(adminid);
        });
        if(adminids.length==0){
            layer.msg("请选择要删除的管理员");
            return ;
        }
        window.location = "${PATH}/admin/batchDel?pageNum=${pageInfo.pageNum}&ids="+adminids.join();
    });


    $(function () {
        $(".list-group-item").click(function(){
            if ( $(this).find("ul") ) {
                $(this).toggleClass("tree-closed");
                if ( $(this).hasClass("tree-closed") ) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });
    });
    $("tbody .btn-success").click(function(){
        window.location.href = "assignRole.html";
    });
    $("tbody .btn-primary").click(function(){
        //获取要更新的管理员id
        //this代表被点击的按钮dom对象  this.属性名
        var adminid = $(this).attr("adminid");
        window.location.href = "${PATH}/admin/edit.html?id="+adminid+"&pageNum=${pageInfo.pageNum}";
    });
</script>
<script type="text/javascript" src="script/manager_highlight.js"></script>
</body>
</html>

